package com.witframework.web.mvc;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.javalid.core.AnnotationValidatorImpl;
import org.javalid.core.ValidationMessage;
import org.javalid.core.config.JvConfiguration;
import org.javalid.core.resource.MessageCodeResourceBundleResolverImpl;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.propertyeditors.CustomMapEditor;
import org.springframework.beans.propertyeditors.CustomBooleanEditor;
import org.springframework.validation.DataBinder;
import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
import org.springframework.web.util.WebUtils;

import com.witframework.PropertiesConstants;
import com.witframework.WitException;
import com.witframework.baseapp.security.UserSession;
import com.witframework.baseapp.security.system.DefaultLogger;
import com.witframework.core.ApplicationProperties;
import com.witframework.core.BaseEntity;
import com.witframework.core.SerialChecker;
import com.witframework.core.WitFrameWork;
import com.witframework.core.annotations.Wit;
import com.witframework.core.log.AuditLogger;
import com.witframework.core.logic.IBaseService;
import com.witframework.core.message.MessageCacheManager;
import com.witframework.core.message.UIMessage;
import com.witframework.core.persistence.PageSortModel;
import com.witframework.core.structure.BaseWitObject;
import com.witframework.optimize.TraceFoot;
import com.witframework.util.BeanUtils;
import com.witframework.util.DateUtil;
import com.witframework.util.StringTools;
import com.witframework.web.file.FileDescriptor;
import com.witframework.web.filter.MultipartWrapper;

/**
 * 
 * @author wuxinyang
 * May 12, 2009 2:34:03 PM
 *
 */
public class WebContext {

	private HttpServletRequest httpRequest;
	private HttpServletResponse httpResponse;
	private static String CONTEXTPATH=null;
	private static Log log = LogFactory.getLog(WebContext.class);

	/**
	 * WebContext的构造方法
	 * @param request -HttpServletRequest请求对象
	 * @param response -HttpServletResponse响应对象
	 */
	public WebContext(HttpServletRequest request, HttpServletResponse response) {
		if(ApplicationProperties.getCall()==1){
			this.httpRequest = request;
			this.httpResponse = response;
		}		
	}
	public HttpServletRequest getHttpRequest() {
		return httpRequest;
	}
	public HttpServletResponse getHttpResponse() {
		return httpResponse;
	}
	public String getCommand(){
		String c=httpRequest.getParameter("command");
		return c!=null?c:"";
	}
	public String getContextPath(){
		initContext(httpRequest);
		return CONTEXTPATH;
	}
	public static void initContext(HttpServletRequest request){
		if(CONTEXTPATH==null){
			CONTEXTPATH=request.getContextPath();			
		}		
	}
	
	public void setAttribute(String name, Object obj) {
		httpRequest.setAttribute(name, obj);
	}
	public void setSessionAttribute(String name, Object obj) {
		httpRequest.getSession().setAttribute(name, obj);
	}
	public Object getSessionAttribute(String name) {
		return httpRequest.getSession().getAttribute(name);
	}
	public String getParameter(String arg0){
		return httpRequest.getParameter(arg0);
	}
	public String getParamOrAttr(String arg0){
		String param=httpRequest.getParameter(arg0);
		if(param==null)
			param=(String)httpRequest.getAttribute(arg0);
		return param;
	}
	/**
	 * 获取表单参数并且放入请求上下文中。也即
	 * 调用httpRequest.getParameter(arg0)和httpRequest.setAttribute(arg0, o)
	 * @param arg0
	 * @return String 表单参数值
	 */
	public String getParameterAndsetAttribute(String arg0){
		String o= httpRequest.getParameter(arg0);
		if(StringUtils.isNotEmpty(o))
			httpRequest.setAttribute(arg0, o);
		return o;
	}
	public String getContextParameterAndsetAttribute(String arg0){
		String o= httpRequest.getParameter(arg0);
		if(o==null)
			o=(String)httpRequest.getAttribute(arg0);
		if(StringUtils.isNotEmpty(o))
			httpRequest.setAttribute(arg0, o);
		return o;
	}
	public String getParameterOrEmpty(String arg0){
		String v=httpRequest.getParameter(arg0);
		return v==null?"":v;
	}
	/**
	 * 绑定表单数据到对象
	 * @param command -表单对象
	 * @param prefix -表单域前缀
	 * @return -表单对象
	 */
	private String prefix="";
	public Object bindObject(Object command,String prefix) {
		if(prefix!=null){
			this.prefix=prefix;
		}		
		SerialChecker.check();
		Map<String, String> parameters = WebUtils.getParametersStartingWith(new ScriptCleanRequestWrapper(httpRequest), prefix);
		MutablePropertyValues mpv = new MutablePropertyValues(parameters);
		DataBinder binder = new DataBinder(command);
		SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.getDatePattern());
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
		binder.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, true));
		binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, true));
		binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, null, true));
		binder.registerCustomEditor(String.class, null, new StringTrimmerEditor(true));
		binder.bind(mpv);      
		if(command instanceof BaseWitObject){
			BaseWitObject be=(BaseWitObject) command;
			String username=getUserName()!=null?getUserName():"";
			if(be.getCreatedby()==null){
				be.setCreatedby(username);
			}
			if(be.getCreated()==null){
				be.setCreated(new java.util.Date());
			}
			be.setUpdatedby(username);
			be.setUpdated(new java.util.Date());
					
		}
		return command;
	}
	/**
	 *  绑定表单数据到对象
	 * @param command 目标对象
	 * @param prefix -表单域前缀
	 * @return -表单对象
	 * @see #bindObject(Object, String)
	 */
	public Object bindObject(Class<?> command,String prefix) {
		try {
			return bindObject(command.newInstance(),prefix);
		} catch (Exception e) {
			throw new WitException("Bind command error.",e);
		}
	}
	/**
	 *  绑定表单数据到对象
	 * @param command 目标对象
	 */
	public Object bindObject(Object command){
		return bindObject(command,null);
	}
	
	/**
	 * 直接输出字符串
	 */
	public void renderString(String content) {
		try {
			httpResponse.setContentType("text/plain;charset=UTF-8");
			httpResponse.getWriter().write(content);

		} catch (IOException e) {
			log.error(e);
		}
	}
	/**
	 * 输出XML
	 * @param content
	 */
	public void renderXml(String content) {
		try {
			httpResponse.setContentType("text/xml;charset=UTF-8");
			httpResponse.getWriter().write(content);

		} catch (IOException e) {
			log.error(e);
		}
	}
	/**
	 * 输出Html 
	 * @param content
	 */
	public void renderHtml(String content) {
		try {
			httpResponse.setContentType("text/html;charset=UTF-8");
			httpResponse.getWriter().write(content);

		} catch (IOException e) {
			log.error(e);
		}
	}
	public String getSelItem(){
		return getSelItem("itemlist");
	}
	public String getSelItem(String checkItemName){
		String[] items=getSelItemList(checkItemName);
		if( items.length>0)
			return items[0];
		return null;
	}
	/**
	 * 数据列表页面的统一标识字段名称，该名称的值取实体的唯一标识值
	 * 在页面中的输入域名称为"itemlist"。
	 */
	public String[] getSelItemList(){		
		return getSelItemList("itemlist");
	}
	/**
	 * 
	 * @param checkItemName 输入域名称
	 * @return 参数值
	 */
	public String[] getSelItemList(String checkItemName){
		if(httpRequest!=null){
			String[] result= httpRequest.getParameterValues(checkItemName);
			return result==null?new String[]{}:result;
		}
		return new String[]{"_NONE_*_"};
	}
	/**
	 * 返回查询过滤器
	 * 页面中的查询过滤器的输入域的名称应该是以"_"开头的
	 * @return Map<String,String>
	 */
	public Map<String,Object> getFilter(){
		if(httpRequest!=null)
			return WebUtils.getParametersStartingWith(httpRequest,"_");
		return new HashMap<String,Object>();
	}

	/**
	 * 是否新增实体,请注意唯一标识的字段名称为"ID"
	 */
	public boolean isNew(BaseEntity entity){		
		return isNew(entity,"id");
	}
	public boolean isNew(BaseEntity entity,String idname){
		if(entity==null)
			return true;
		try {
			String id= (String) BeanUtils.getDeclaredProperty(entity,idname);
			if(null!=id&&id.length()>0){
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}
	/**
	 *构造分页模型
	 *@param table_id -ec table的tableId,如果该值为null则取默认的名称"ec"
	 *			该值必须和页面的ec table的id设置值一致。
	 */
	public PageSortModel getPageSortModel(String table_id){
		if(table_id==null){
			table_id=(String)httpRequest.getParameter("ec_i");
		}
		return new PageSortModel(httpRequest,table_id);
	}
	/**
	 * 返回分页模型对象
	 * @return -分页模型对象
	 */
	public PageSortModel getPageSortModel(){
		return getPageSortModel(null);
	}
	/**
	 * 设置WEB页面消息
	 * @param message 消息内容
	 * @param type 消息类型：可以为
	 *  ActionMessage.ERROR：错误消息
	 *  ActionMessage.INFO:提示消息
	 *  ActionMessage.WARNING:警告类型消息
	 */
	private void setActionMessage(String message,int type){		
		cacheMessage(message,type);
		if(httpRequest!=null){
			List<String> messages = (List<String>) WebUtils.getOrCreateSessionAttribute(httpRequest.getSession(), "actionMessages", ArrayList.class);
			messages.add(message);
		}
	}
	/**
	 * 设置提示消息
	 * @param message
	 */
	public void setPageInfo(String message){
		setActionMessage(message,UIMessage.INFO);
	}
	/**
	 * 设置错误消息
	 * @param message
	 *  @see #setPageInfo(String)
	 */
	public void setPageError(String message){
		setActionMessage(message,UIMessage.ERROR);
	}
	/**
	 * 设置警告消息
	 * @param message
	 * @see #setPageInfo(String)
	 */
	public void setPageWarning(String message){
		setActionMessage(message,UIMessage.WARNING);
	}
	/**
	 * 向页面设置javascript代码，设置的代码会以页面消息的形式到达页面
	 * @param script javascript代码
	 * @see #setPageInfo(String)
	 */
	public void setPageScript(String script){
		setActionMessage("<script>"+script+"</script>",UIMessage.INFO);
	}
	/**
	 * 获取资源消息串，用于本地化，查询一个特定语言环境的资源
	 * @param code 代码
	 * @param param 参数，用于替换资源串中的变量
	 * @return 本地化资源串
	 */
	public String getMessage(String code,Object[] param){
		org.springframework.context.support.ResourceBundleMessageSource ms=(org.springframework.context.support.ResourceBundleMessageSource)com.witframework.core.BeanFactory.getBean("messageSource");
		if(httpRequest!=null){
			String msg=ms.getMessage(code, param,code, httpRequest.getLocale());
			return msg;
		}
		return code;
	}
	/**
	 * 获取资源消息串，用于本地化，查询一个特定语言环境的资源
	 * @param code 代码
	 * @return 本地化资源串
	 * @see #getMessage(String, Object[])
	 */
	public String getMessage(String code){
		return getMessage(code,null);
	}
	/**
	 * 缓存消息
	 * @param msg
	 * @param msgType
	 */
	private void cacheMessage(String msg,int msgType){
		UIMessage message=new UIMessage(msg,msgType);
		if(message.getId()!=null){
		MessageCacheManager.getInstance().store(message);
		String messagerequestids=(String)WebUtils.getSessionAttribute(httpRequest, "messagerequestids");
		if(messagerequestids!=null&&messagerequestids.length()>0)
			messagerequestids=messagerequestids+","+message.getId();
		else{
			messagerequestids=message.getId();
		}
		WebUtils.setSessionAttribute(httpRequest,"messagerequestids", messagerequestids);
		}
	}
	public void sendRedirect(String url){
		try {
			if(!url.startsWith(httpRequest.getContextPath()))
				url=httpRequest.getContextPath()+url;
			this.httpResponse.sendRedirect(url);
		} catch (IOException e) {
			throw new WitException(e);
		}
	}
	/**
	 * 验证数据有效性
	 * @param obj
	 * @return 是否通过验证
	 */
	private boolean validateObject(Object obj){
		String validateMessage="发生错误:";
		List<ValidationMessage> messages = null;
		AnnotationValidatorImpl validator = new AnnotationValidatorImpl(JvConfiguration.JV_CONFIG_FILE_FIELD_WITH_MSG_RESOLVING);
		validator.setMessageCodeResolver(new MessageCodeResourceBundleResolverImpl(
				new String[]{"jv_messages","ValidationMessages"}));
		messages = validator.validateObject(obj);
		messages.addAll(validator.validateObject(obj,"inheritance"));
		if(messages.size()>1)
			validateMessage+="<BR>";
		for(ValidationMessage vm:messages){
			Wit wit=null;
			try {
				wit =BeanUtils.getDeclaredField(obj,vm.getPath()).getAnnotation(Wit.class);
			} catch (Exception e) {				
			}
			String errorMes=vm.getResolvedMessage();
			if(errorMes.length()>80){
				errorMes=errorMes.substring(0,80)+"(...略)";
			}				
			if(wit!=null&&StringUtils.isNotEmpty(wit.cnname())){
				validateMessage+="'"+wit.cnname()+"'"+errorMes;	
			}else{
				validateMessage+=vm.getPath()+" "+errorMes;
			}
			validateMessage+="<BR>";
		}
		boolean hasHdivError=false;
		/**		
		String _hdiv_ignoreParameters=httpRequest.getParameter("_hdiv_ignoreParameters");		
		Validator hdiv=(Validator)BeanFactory.getBean("editableParemetersValidator");	
		String uri=this.httpRequest.getRequestURI();
		Field[] feilds=obj.getClass().getDeclaredFields();
		for(Field f:feilds){
			String p=f.getName();
			if(_hdiv_ignoreParameters==null||_hdiv_ignoreParameters.toLowerCase().indexOf(","+p.toLowerCase())>0||_hdiv_ignoreParameters.toLowerCase().equalsIgnoreCase(p.toLowerCase()))
				continue;
			String[] vs=httpRequest.getParameterValues(prefix+p);	
			if(vs==null||vs.length==0){
				String v=httpRequest.getParameter(prefix+p);
				if(v!=null)
					vs=new String[]{v};
			}
			if(vs!=null&&vs.length>0){
				List<String> hdivMsg=hdiv.editableParameterValuesValid(uri,p,vs);
				if(hdivMsg.size()>0){
					String error=null;
					Wit wit=null;
					try {
						wit =BeanUtils.getDeclaredField(obj,p).getAnnotation(Wit.class);
						if(wit!=null&&StringUtils.isNotEmpty(wit.cnname())){
							error="'"+wit.cnname()+"'";	
						}else{
							error=p;
						}
					} catch (Exception e) {				
					}
					for(String msg:hdivMsg){
						error+=msg;					
					}
					hasHdivError=true;
					validateMessage+=error;
					validateMessage+="<BR>";
				}
			}
		}	
		**/
		if(messages.size()>0||hasHdivError){
			setPageError(validateMessage);
			return false;
		}
		return true;
	}
	/**
	 * 验证数据有效性
	 * @param name 对象名称，注意：使用该名称调用：httpRequest.setAttribute(name,obj);
	 * @param obj 要验证的对象
	 * @param url 验证失败后的重定向URL
	 */
	public void validateObject(String name,Object obj,String url){
		if(url==null)
			url=(String)httpRequest.getSession().getAttribute("front.page");
		if(!validateObject(obj)){
			this.httpRequest.setAttribute(name,obj);
			throw new ObjectValidateException(url);
		}
	}
	/**
	 * 添加访问足迹，URL从httpRequest.getRequestURI(）获取
	 * @param id 足迹ID
	 * @param name 足迹名称
	 */
	public void addFootmark(String id,String name){
		String query=httpRequest.getQueryString();
		getTraceFootSession().addFootmark(id,name,httpRequest.getRequestURI()+(query==null?"":"?"+query));
	}
	/**
	 * 添加导航跟踪，导航的URL从httpRequest.getRequestURI(）获取
	 * @param id 导航ID
	 * @param name 导航名称	
	 */
	public void addNavigateTrace(String id,String name){
		String query=httpRequest.getQueryString();
		getTraceFootSession().addNavigateTrace(id,name,httpRequest.getRequestURI()+(query==null?"":"?"+query));
	}
	/**
	 * 获取当前导航的URL,系统自动定向该URL
	 * 在需要自动导航的地方调用代码addNavigateTrace(String id,String name)
	 * @param id
	 * @return
	 */
	public String getTraceNavigate(String id){		
		return null;
		//return getTraceFootSession().getAutoNavigateUrl(id);
	}
	/**
	 * 添加访问足迹
	 * @param id 足迹ID
	 * @param name 足迹名称
	 * @param url 足迹URL
	 */
	public void addFootmark(String id,String name,String url){
		getTraceFootSession().addFootmark(id,name,url);
	}
	/**
	 * 获取访问足迹
	 * @param id 足迹ID
	 * @return String[]{足迹名称,足迹URL}
	 */
	public String[] getFootmark(String id){
		//return getTraceFootSession().getFootmark(id);
		return null;
	}
	/**
	 * 添加导航跟踪
	 * @param id 导航ID
	 * @param name 导航名称
	 * @param url URL
	 */
	public void addNavigateTrace(String id,String name,String url){
		getTraceFootSession().addNavigateTrace(id,name,url);
	}
	private TraceFoot getTraceFootSession(){
		return null;
//		if(getUserSession()==null)
//			throw new WitException("安全错误，尚未登录系统或登录信息已过期！请重新登录");
//		return TraceFoot.getInstance(getUserSession().getUser().getUsername());
		
	}
	public UserSession getUserSession(){
		return (UserSession)getSessionAttribute("UserSession");
	}
	public String getUserName(){
		UserSession us=getUserSession();
		return us!=null?getUserSession().getUser().getUsername():null;
	}
	public void setUserSession(UserSession userSession){
		this.setSessionAttribute("UserSession", userSession);
	}
	public String forward(WebContext webContext){
		String target=webContext.getHttpRequest().getQueryString();		
		return target;
	}
	/**
	 * 生成调用sendRedirect方法转发的目标地址
	 * @param url 目标地址
	 * @return WitDispatcher可以解析的目标地址
	 */
	public static String redirectView(String url){
		return "redirect:"+url;
	}
	/**
	 * 生成的目标地址指向/WEB-INF/classes/%url%
	 * @param url 目标地址
	 * @return WitDispatcher可以解析的目标地址
	 */
	public static String classpathView(String url){
		return "classpath:"+url;
	}
	/**
	 * 生成的目标地址指向：%当前处理的类路径%/view/当前处理器处理的Entity类名/%url%
	 * @param url 目标地址
	 * @return WitDispatcher可以解析的目标地址	 
	 */
	public static String domainView(String url){
		return "//:"+url;
	}
	/**
	 * 生成的目标地址指向：处理器包的父包类路径/%url%
	 * @param url 目标地址
	 * @return WitDispatcher可以解析的目标地址
	 */
	public static String packageView(String url){
		return "package:"+url;
	}
	
	/**
	 * 生成的目标地址指向：/WEB-INF/classes/%处理器包路径%/%url%
	 * @param url
	 * @return WitDispatcher可以解析的目标地址
	 */
	public static String cpCtrView(String url){
		return "controller:"+url;
	}
	/**
	 * 生成的目标地址指向：/WEB-INF/classes/%处理器包的父包类路径%/%url%
	 * @param url
	 * @return WitDispatcher可以解析的目标地址
	 */
	public static String cpCtrParentView(String url){
		return "parent:"+url;
	}
	
	public void log(String operation,String code,String description,String objectid,String xml){
		AuditLogger auditLogger=new DefaultLogger();
		auditLogger.info(getUserName(),new java.util.Date(),code, description,
				new java.util.Date(), getHttpRequest().getRemoteAddr(),
				operation,objectid,xml);
	}	
	public void log(String operation,String code,String description){		
		log(operation,code,description,"","");
	}
	public void log(String operation,String description){		
		log(operation,AuditLogger.INFO,description,"","");
	}
	public void log(String operation){		
		log(operation,AuditLogger.INFO,"","","");
	}
	public Object newEntity(IBaseService service,Object entity){
		return newEntity(service,entity,"");
	}
	public Object newEntity(IBaseService service,Object entity,String prefix){
		String id=this.httpRequest.getParameter(prefix+"id");
		if(id!=null){
			Object o=service.get(this.httpRequest.getParameter(prefix+"id"));
			if(o!=null) entity=o;
		}
		return entity;
	}	
	public List<FileDescriptor> getFiles(){
	   	if (!(httpRequest instanceof MultipartWrapper))
	   		return null;
	   	List<FileDescriptor> fileDescriptors = new ArrayList<FileDescriptor>();
	   	MultipartWrapper multi = (MultipartWrapper) httpRequest;
	   	Enumeration<String> fileNames = multi.getFileNames();
	   	while (fileNames.hasMoreElements()) {
	   		String name = (String) fileNames.nextElement();
	   		File file=multi.getFile(name);
	   		multi.getOriginalFileName(name);
	   		if (file != null) {	   			
	   			FileDescriptor fileDescriptor = new FileDescriptor();
	   			fileDescriptor.setName(name);
	   			fileDescriptor.setFile(file);
	   			fileDescriptor.setFilesystemName(multi.getFilesystemName(name));	   			
	   			fileDescriptor.setOriginalFileName(multi.getOriginalFileName(name));
	   			fileDescriptor.setContentType(multi.getContentType(multi.getOriginalFileName(name)));	   	
	   			fileDescriptors.add(fileDescriptor);
	   		}
	   	}
	   	return fileDescriptors;	   
	}
	public String uploadToDir(String uploadDir,String parameterName){
		
		MultipartWrapper multi = null;
        if(httpRequest instanceof MultipartWrapper){
        	multi=(MultipartWrapper)httpRequest;
        	File file=multi.getFile(parameterName);
        	String originalFileName = multi.getOriginalFileName(parameterName);        	
            if (file!=null){
            	File dir;
            	String basefolder=ApplicationProperties.getProperty(PropertiesConstants.FILE_UPLOAD_FOLDER);
            	if(StringUtils.isNotEmpty(basefolder)){
            		dir=new File(basefolder+File.separator+uploadDir);
            	}else{
            		dir=new File(WitFrameWork.getWebApplicationContext().getServletContext().getRealPath(uploadDir));
            	}            	
            	if(!dir.exists())
            		dir.mkdirs();
                String fileRealPath =dir.getAbsolutePath()+ File.separator + originalFileName;
                File newfile = new File(fileRealPath);
                if(newfile.exists()){
                	newfile=new com.oreilly.servlet.multipart.DefaultFileRenamePolicy().rename(newfile);
                	newfile.delete();
                }
                file.renameTo(newfile);
                return newfile.getName();
            }
        }
        return null;
	}
}
final class ScriptCleanRequestWrapper extends HttpServletRequestWrapper{
	private HttpServletRequest request;
	private String exclude_escape_input_fileds=null;
	public ScriptCleanRequestWrapper(HttpServletRequest request) {
		super(request);
		this.request=request;
		exclude_escape_input_fileds=request.getParameter("exclude_escape_input_fileds");
		if(exclude_escape_input_fileds!=null) exclude_escape_input_fileds+=",";
	}
	@Override
	public String getParameter(String name){
		String charset=request.getCharacterEncoding();
		String value= request.getParameter(name);
		if((exclude_escape_input_fileds==null||exclude_escape_input_fileds.indexOf(name)==-1)&&value!=null){
			value=StringTools.escapeHTML(value);
		}
		return value;
	}
	@Override
	public String[] getParameterValues(String name){
		String charset=request.getCharacterEncoding();
		String[] values=request.getParameterValues(name);
		if((exclude_escape_input_fileds==null||exclude_escape_input_fileds.indexOf(name)==-1)&&values!=null){
    		for(int i=0;i<values.length;i++){
    			values[i]=StringTools.escapeHTML(values[i]);
    		}
		}
		return values;
	}
}